/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uno;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author abelitro
 */
public class Computation extends Thread{
    
    private int num;
    private boolean isCompleate;
    private int result;
    
    public Computation(int num){this.num=num;}
    
    public synchronized void run(){
        result = num*2;
        isCompleate = true;
        notify();
    }
    public synchronized int getResult(){
        while(!isCompleate){
            try {
                wait();
            } catch (InterruptedException ex) {
                Logger.getLogger(Computation.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return result;
    }
    public static void main(String args[]){
        Computation[] computations = new Computation[4];
        for(int i = 0; i<4;i++){
            computations[i] = new Computation(i);
            computations[i].start();
        }
        for(Computation c : computations){
            System.out.println(c.getResult());
        }
    }
}
